public class Text {
    //合并两个有序链表
    public static MySingleList.ListNode mergeTwoLists(MySingleList.ListNode head1, MySingleList.ListNode head2) {
        MySingleList.ListNode newNode = new MySingleList.ListNode(0);
        MySingleList.ListNode tmp = newNode;
        while (head1 != null&& head2 != null) {
            if (head1.val <= head2.val) {
                tmp.next =head1;
                head1 = head1.next;
                tmp = tmp.next;
            }else {
                tmp.next =head2;
                head2 = head2.next;
                tmp = tmp.next;
            }
        }
        if (head1 != null ) {
            tmp.next = head1;
        }
        if (head2 != null ) {
            tmp.next = head2;
        }
        return newNode.next;
    }

    public static void main(String[] args) {
        MyLinkedList myLinkedList = new MyLinkedList();
        myLinkedList.addFirst(1);
        myLinkedList.addFirst(2);
        myLinkedList.addFirst(3);
        myLinkedList.addFirst(3);
        myLinkedList.addFirst(3);
        myLinkedList.addFirst(3);
        myLinkedList.addFirst(3);
        myLinkedList.addFirst(4);
        myLinkedList.addFirst(5);
        myLinkedList.removeAllKey(3);
        myLinkedList.display();
        /*myLinkedList.addLast(6);
        myLinkedList.addLast(7);
        myLinkedList.display();
        myLinkedList.addIndex(7,8);
        myLinkedList.remove(8);
        myLinkedList.display();*/
    }
    public static void main3(String[] args) {
        MySingleList mySingleList1 = new MySingleList();
        mySingleList1.addLast(11);
        mySingleList1.addLast(22);
        mySingleList1.addLast(44);
        mySingleList1.addLast(55);
        MySingleList mySingleList2 = new MySingleList();
        mySingleList2.addLast(15);
        mySingleList2.addLast(25);
        mySingleList2.addLast(42);
        mySingleList2.addLast(59);
        MySingleList.ListNode  ret = mergeTwoLists(mySingleList1.head,mySingleList2.head);
        mySingleList2.display(ret);

    }
    public static void main2(String[] args) {
        MySingleList mySingleList = new MySingleList();
        mySingleList.addLast(1);
        mySingleList.addLast(2);
        mySingleList.addLast(3);
        mySingleList.addLast(4);
        mySingleList.display();
        System.out.println("=================");
        MySingleList.ListNode  ret = mySingleList.reverseList();
        mySingleList.display(ret.next);
    }
    public static void main1(String[] args) {
        MySingleList mySingleList = new MySingleList();
       // mySingleList.createLink();
        mySingleList.addFirst(5);
        mySingleList.addFirst(1);
        mySingleList.addFirst(2);
        mySingleList.addFirst(5);
        mySingleList.addFirst(3);
        mySingleList.addLast(5);
        mySingleList.display();
        mySingleList.addIndex(2,7);
        System.out.println("==================");
        mySingleList.remove(3);
        System.out.println("================");
        mySingleList.display();
        System.out.println("===============");
        mySingleList.removeAllKey(5);
        mySingleList.display();


    }
}
